﻿using System;
using System.Data;
using System.Collections.Generic;
using DocViewer.Common;
using DY.Model;
namespace DY.BLL
{
    /// <summary>
    /// View_UserWithProtocol
    /// </summary>
    public partial class View_UserWithProtocol
    {
        private readonly DY.DAL.View_UserWithProtocol dal = new DY.DAL.View_UserWithProtocol();
        public View_UserWithProtocol()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(DY.Model.View_UserWithProtocol model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DY.Model.View_UserWithProtocol model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DY.Model.View_UserWithProtocol GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public DY.Model.View_UserWithProtocol GetModelByCache(int id)
        {

            string CacheKey = "View_UserWithProtocolModel-" + id;
            object objModel = DocViewer.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = DocViewer.Common.ConfigHelper.GetConfigInt("ModelCache");
                        DocViewer.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (DY.Model.View_UserWithProtocol)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<DY.Model.View_UserWithProtocol> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<DY.Model.View_UserWithProtocol> DataTableToList(DataTable dt)
        {
            List<DY.Model.View_UserWithProtocol> modelList = new List<DY.Model.View_UserWithProtocol>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                DY.Model.View_UserWithProtocol model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new DY.Model.View_UserWithProtocol();
                    if (dt.Rows[n]["CardId"] != null && dt.Rows[n]["CardId"].ToString() != "")
                    {
                        model.CardId = dt.Rows[n]["CardId"].ToString();
                    }
                    if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["VillageName"] != null && dt.Rows[n]["VillageName"].ToString() != "")
                    {
                        model.VillageName = dt.Rows[n]["VillageName"].ToString();
                    }
                    if (dt.Rows[n]["Population"] != null && dt.Rows[n]["Population"].ToString() != "")
                    {
                        model.Population = int.Parse(dt.Rows[n]["Population"].ToString());
                    }
                    if (dt.Rows[n]["Mobile"] != null && dt.Rows[n]["Mobile"].ToString() != "")
                    {
                        model.Mobile = dt.Rows[n]["Mobile"].ToString();
                    }
                    if (dt.Rows[n]["Photo"] != null && dt.Rows[n]["Photo"].ToString() != "")
                    {
                        model.Photo = dt.Rows[n]["Photo"].ToString();
                    }
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["ProtocolId"] != null && dt.Rows[n]["ProtocolId"].ToString() != "")
                    {
                        model.ProtocolId = dt.Rows[n]["ProtocolId"].ToString();
                    }
                    if (dt.Rows[n]["ProtocolType"] != null && dt.Rows[n]["ProtocolType"].ToString() != "")
                    {
                        model.ProtocolType = dt.Rows[n]["ProtocolType"].ToString();
                    }
                    if (dt.Rows[n]["OwnerId"] != null && dt.Rows[n]["OwnerId"].ToString() != "")
                    {
                        model.OwnerId = int.Parse(dt.Rows[n]["OwnerId"].ToString());
                    }
                    if (dt.Rows[n]["Chai_Time"] != null && dt.Rows[n]["Chai_Time"].ToString() != "")
                    {
                        model.Chai_Time = DateTime.Parse(dt.Rows[n]["Chai_Time"].ToString());
                    }
                    if (dt.Rows[n]["Chai_Structure"] != null && dt.Rows[n]["Chai_Structure"].ToString() != "")
                    {
                        model.Chai_Structure = dt.Rows[n]["Chai_Structure"].ToString();
                    }
                    if (dt.Rows[n]["Chai_MainCovers"] != null && dt.Rows[n]["Chai_MainCovers"].ToString() != "")
                    {
                        model.Chai_MainCovers = decimal.Parse(dt.Rows[n]["Chai_MainCovers"].ToString());
                    }
                    if (dt.Rows[n]["Chai_MainArea"] != null && dt.Rows[n]["Chai_MainArea"].ToString() != "")
                    {
                        model.Chai_MainArea = decimal.Parse(dt.Rows[n]["Chai_MainArea"].ToString());
                    }
                    if (dt.Rows[n]["Chai_AttachedCovers"] != null && dt.Rows[n]["Chai_AttachedCovers"].ToString() != "")
                    {
                        model.Chai_AttachedCovers = decimal.Parse(dt.Rows[n]["Chai_AttachedCovers"].ToString());
                    }
                    if (dt.Rows[n]["Chai_AttachedArea"] != null && dt.Rows[n]["Chai_AttachedArea"].ToString() != "")
                    {
                        model.Chai_AttachedArea = decimal.Parse(dt.Rows[n]["Chai_AttachedArea"].ToString());
                    }
                    if (dt.Rows[n]["Chai_Fangqianwuhou"] != null && dt.Rows[n]["Chai_Fangqianwuhou"].ToString() != "")
                    {
                        model.Chai_Fangqianwuhou = decimal.Parse(dt.Rows[n]["Chai_Fangqianwuhou"].ToString());
                    }
                    if (dt.Rows[n]["Chai_ReclamationLotNo"] != null && dt.Rows[n]["Chai_ReclamationLotNo"].ToString() != "")
                    {
                        model.Chai_ReclamationLotNo = dt.Rows[n]["Chai_ReclamationLotNo"].ToString();
                    }
                    if (dt.Rows[n]["An_Time"] != null && dt.Rows[n]["An_Time"].ToString() != "")
                    {
                        model.An_Time = DateTime.Parse(dt.Rows[n]["An_Time"].ToString());
                    }
                    if (dt.Rows[n]["An_Type"] != null && dt.Rows[n]["An_Type"].ToString() != "")
                    {
                        model.An_Type = dt.Rows[n]["An_Type"].ToString();
                    }
                    if (dt.Rows[n]["An_Address"] != null && dt.Rows[n]["An_Address"].ToString() != "")
                    {
                        model.An_Address = dt.Rows[n]["An_Address"].ToString();
                    }
                    if (dt.Rows[n]["An_HouseNo"] != null && dt.Rows[n]["An_HouseNo"].ToString() != "")
                    {
                        model.An_HouseNo = dt.Rows[n]["An_HouseNo"].ToString();
                    }
                    if (dt.Rows[n]["An_Covers"] != null && dt.Rows[n]["An_Covers"].ToString() != "")
                    {
                        model.An_Covers = decimal.Parse(dt.Rows[n]["An_Covers"].ToString());
                    }
                    if (dt.Rows[n]["An_Area"] != null && dt.Rows[n]["An_Area"].ToString() != "")
                    {
                        model.An_Area = decimal.Parse(dt.Rows[n]["An_Area"].ToString());
                    }
                    if (dt.Rows[n]["An_BuildType"] != null && dt.Rows[n]["An_BuildType"].ToString() != "")
                    {
                        model.An_BuildType = dt.Rows[n]["An_BuildType"].ToString();
                    }
                    if (dt.Rows[n]["Fei_ShiGongBaoZhengJin"] != null && dt.Rows[n]["Fei_ShiGongBaoZhengJin"].ToString() != "")
                    {
                        model.Fei_ShiGongBaoZhengJin = decimal.Parse(dt.Rows[n]["Fei_ShiGongBaoZhengJin"].ToString());
                    }
                    if (dt.Rows[n]["Fei_WeiYueFaKuan"] != null && dt.Rows[n]["Fei_WeiYueFaKuan"].ToString() != "")
                    {
                        model.Fei_WeiYueFaKuan = decimal.Parse(dt.Rows[n]["Fei_WeiYueFaKuan"].ToString());
                    }
                    if (dt.Rows[n]["Fei_DaiJianShuiNiYingHua"] != null && dt.Rows[n]["Fei_DaiJianShuiNiYingHua"].ToString() != "")
                    {
                        model.Fei_DaiJianShuiNiYingHua = decimal.Parse(dt.Rows[n]["Fei_DaiJianShuiNiYingHua"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ChaiJiaJiangLi"] != null && dt.Rows[n]["Fei_ChaiJiaJiangLi"].ToString() != "")
                    {
                        model.Fei_ChaiJiaJiangLi = decimal.Parse(dt.Rows[n]["Fei_ChaiJiaJiangLi"].ToString());
                    }
                    if (dt.Rows[n]["Fei_AnZhiYanQiBuChang"] != null && dt.Rows[n]["Fei_AnZhiYanQiBuChang"].ToString() != "")
                    {
                        model.Fei_AnZhiYanQiBuChang = decimal.Parse(dt.Rows[n]["Fei_AnZhiYanQiBuChang"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ShiGongShuiDianFei"] != null && dt.Rows[n]["Fei_ShiGongShuiDianFei"].ToString() != "")
                    {
                        model.Fei_ShiGongShuiDianFei = decimal.Parse(dt.Rows[n]["Fei_ShiGongShuiDianFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ShuiBiaoKaiHuFei"] != null && dt.Rows[n]["Fei_ShuiBiaoKaiHuFei"].ToString() != "")
                    {
                        model.Fei_ShuiBiaoKaiHuFei = decimal.Parse(dt.Rows[n]["Fei_ShuiBiaoKaiHuFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_DianBiaoAnZhuangFei"] != null && dt.Rows[n]["Fei_DianBiaoAnZhuangFei"].ToString() != "")
                    {
                        model.Fei_DianBiaoAnZhuangFei = decimal.Parse(dt.Rows[n]["Fei_DianBiaoAnZhuangFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_LaJiQingYunFei"] != null && dt.Rows[n]["Fei_LaJiQingYunFei"].ToString() != "")
                    {
                        model.Fei_LaJiQingYunFei = decimal.Parse(dt.Rows[n]["Fei_LaJiQingYunFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_DiJiBuChaFei"] != null && dt.Rows[n]["Fei_DiJiBuChaFei"].ToString() != "")
                    {
                        model.Fei_DiJiBuChaFei = decimal.Parse(dt.Rows[n]["Fei_DiJiBuChaFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ZhengCeXingBuZhu"] != null && dt.Rows[n]["Fei_ZhengCeXingBuZhu"].ToString() != "")
                    {
                        model.Fei_ZhengCeXingBuZhu = decimal.Parse(dt.Rows[n]["Fei_ZhengCeXingBuZhu"].ToString());
                    }
                    if (dt.Rows[n]["Fei_GuoDuQiFangZu"] != null && dt.Rows[n]["Fei_GuoDuQiFangZu"].ToString() != "")
                    {
                        model.Fei_GuoDuQiFangZu = decimal.Parse(dt.Rows[n]["Fei_GuoDuQiFangZu"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ChaiJiuFei"] != null && dt.Rows[n]["Fei_ChaiJiuFei"].ToString() != "")
                    {
                        model.Fei_ChaiJiuFei = decimal.Parse(dt.Rows[n]["Fei_ChaiJiuFei"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ShiJiaoFeiYong"] != null && dt.Rows[n]["Fei_ShiJiaoFeiYong"].ToString() != "")
                    {
                        model.Fei_ShiJiaoFeiYong = decimal.Parse(dt.Rows[n]["Fei_ShiJiaoFeiYong"].ToString());
                    }
                    if (dt.Rows[n]["Fei_YiJiaoShuE"] != null && dt.Rows[n]["Fei_YiJiaoShuE"].ToString() != "")
                    {
                        model.Fei_YiJiaoShuE = decimal.Parse(dt.Rows[n]["Fei_YiJiaoShuE"].ToString());
                    }
                    if (dt.Rows[n]["Fei_WeiJiaoShuE"] != null && dt.Rows[n]["Fei_WeiJiaoShuE"].ToString() != "")
                    {
                        model.Fei_WeiJiaoShuE = decimal.Parse(dt.Rows[n]["Fei_WeiJiaoShuE"].ToString());
                    }
                    if (dt.Rows[n]["Remark"] != null && dt.Rows[n]["Remark"].ToString() != "")
                    {
                        model.Remark = dt.Rows[n]["Remark"].ToString();
                    }
                    if (dt.Rows[n]["ProtocolPhoto"] != null && dt.Rows[n]["ProtocolPhoto"].ToString() != "")
                    {
                        model.ProtocolPhoto = dt.Rows[n]["ProtocolPhoto"].ToString();
                    }
                    if (dt.Rows[n]["Fei_YingJiaoShuE"] != null && dt.Rows[n]["Fei_YingJiaoShuE"].ToString() != "")
                    {
                        model.Fei_YingJiaoShuE = decimal.Parse(dt.Rows[n]["Fei_YingJiaoShuE"].ToString());
                    }
                    if (dt.Rows[n]["An_ChaiJianNo"] != null && dt.Rows[n]["An_ChaiJianNo"].ToString() != "")
                    {
                        model.An_ChaiJianNo = dt.Rows[n]["An_ChaiJianNo"].ToString();
                    }
                    if (dt.Rows[n]["An_ChaiJianArea"] != null && dt.Rows[n]["An_ChaiJianArea"].ToString() != "")
                    {
                        model.An_ChaiJianArea = decimal.Parse(dt.Rows[n]["An_ChaiJianArea"].ToString());
                    }
                    if (dt.Rows[n]["An_GeLou"] != null && dt.Rows[n]["An_GeLou"].ToString() != "")
                    {
                        model.An_GeLou = int.Parse(dt.Rows[n]["An_GeLou"].ToString());
                    }
                    if (dt.Rows[n]["Fei_FangKuanShuE"] != null && dt.Rows[n]["Fei_FangKuanShuE"].ToString() != "")
                    {
                        model.Fei_FangKuanShuE = decimal.Parse(dt.Rows[n]["Fei_FangKuanShuE"].ToString());
                    }
                    if (dt.Rows[n]["Fei_GeLouJinE"] != null && dt.Rows[n]["Fei_GeLouJinE"].ToString() != "")
                    {
                        model.Fei_GeLouJinE = decimal.Parse(dt.Rows[n]["Fei_GeLouJinE"].ToString());
                    }
                    if (dt.Rows[n]["Fei_ChaiJianJinE"] != null && dt.Rows[n]["Fei_ChaiJianJinE"].ToString() != "")
                    {
                        model.Fei_ChaiJianJinE = decimal.Parse(dt.Rows[n]["Fei_ChaiJianJinE"].ToString());
                    }
                    if (dt.Rows[n]["An_HuXing"] != null && dt.Rows[n]["An_HuXing"].ToString() != "")
                    {
                        model.An_HuXing = dt.Rows[n]["An_HuXing"].ToString();
                    }
                    if (dt.Rows[n]["An_TaoShu"] != null && dt.Rows[n]["An_TaoShu"].ToString() != "")
                    {
                        model.An_TaoShu = int.Parse(dt.Rows[n]["An_TaoShu"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

